import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/newBigDataScreen',
    component: () => import('@/views/newBigDataScreen/index'),
    name: 'newBigDataScreen',
    meta: { title: '数据大屏', icon: 'dashboard', affix: true }
  },
  {
    path: '/',
    component: Layout,
    redirect: '/homePage',
    children: [
      {
        path: 'homePage',
        component: () => import('@/views/homePage/index'),
        name: 'homePage',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  }

]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  {
    id: 1,
    path: '/parking',
    component: Layout,
    name: 'parking',
    meta: {
      title: '停车场管理',
      icon: 'nested'
    },
    children: [
      {
        id: 101,
        path: 'parkingManage',
        component: () => import('@/views/parking/parkingManage'),
        name: 'parkingManage',
        meta: { title: '停车场管理', icon: 'guide' }
      },
      {
        id: 102,
        path: 'parkingOwner',
        component: () => import('@/views/parking/parkingOwner'),
        name: 'parkingOwner',
        meta: { title: '车场主管理', icon: 'guide' }
      }
    ]
  },
  {
    id: 2,
    path: '/inOutPark',
    component: Layout,
    name: 'inOutPark',
    meta: { title: '出入场管理', icon: 'nested' },
    children: [
      {
        id: 201,
        path: 'inOutPark',
        component: () => import('@/views/inOutPark/index'),
        name: 'inOutPark',
        meta: { title: '出入场管理', icon: 'nested' }
      }
    ]
  },
  {
    id: 20,
    path: '/outParkPay',
    component: Layout,
    name: 'outParkPay',
    meta: { title: '出场缴费管理', icon: 'nested' },
    children: [
      {
        id: 2001,
        path: 'outParkPay',
        component: () => import('@/views/outParkPay/index'),
        name: 'outParkPay',
        meta: { title: '出场缴费管理', icon: 'nested' }
      }
    ]
  },
  {
    id: 3,
    path: '/member',
    component: Layout,
    name: 'member',
    meta: { title: '会员管理', icon: 'nested' },
    children: [
      {
        id: 301,
        path: 'member',
        component: () => import('@/views/member/index'),
        name: 'member',
        meta: { title: '会员管理', icon: 'nested' }
      }
    ]
  },
  {
    id: 4,
    path: '/marketing',
    component: Layout,
    name: 'marketing',
    meta: { title: '营销管理', icon: 'nested' },
    children: [
      {
        id: 401,
        path: 'coupon',
        component: () => import('@/views/marketing/coupon/index'),
        name: 'coupon',
        meta: { title: '优惠券', icon: 'nested' }
      },
      {
        id: 402,
        path: 'parkingTicket',
        component: () => import('@/views/marketing/parkingTicket/index'),
        name: 'parkingTicket',
        meta: { title: '停车券', icon: 'nested' }
      },
      {
        id: 403,
        path: 'ticketGrantSituation',
        component: () => import('@/views/marketing/ticketGrantSituation/index'),
        name: 'ticketGrantSituation',
        meta: { title: '商户停车券发放情况', icon: 'nested' }
      },
      {
        id: 404,
        path: 'ticketUseSituation',
        component: () => import('@/views/marketing/ticketUseSituation/index'),
        name: 'ticketUseSituation',
        meta: { title: '停车券使用情况', icon: 'nested' }
      }
    ]
  },
  {
    id: 5,
    path: '/service',
    component: Layout,
    name: 'service',
    meta: { title: '服务项目管理', icon: 'nested' },
    children: [
      {
        id: 501,
        path: 'service',
        component: () => import('@/views/service/index'),
        name: 'service',
        meta: { title: '服务项目管理', icon: 'nested' }
      }
    ]
  },
  {
    // id: 5,
    path: '/appointment',
    component: Layout,
    name: 'appointment',
    meta: { title: '预约管理', icon: 'nested' },
    children: [
      {
        // id: 501,
        path: 'appointment',
        component: () => import('@/views/appointment/index'),
        name: 'appointment',
        meta: { title: '预约管理', icon: 'nested' }
      }
    ]
  },
  {
    id: 6,
    path: '/finance',
    component: Layout,
    name: 'finance',
    meta: {
      title: '财务管理',
      icon: 'nested'
    },
    children: [
      {
        id: 601,
        path: 'flowingWater',
        component: () => import('@/views/finance/flowingWater'),
        name: 'flowingWater',
        meta: { title: '平台账号记录', icon: 'guide' }
      },
      // {
      //   id: 602,
      //   path: 'rechargeRecord',
      //   component: () => import('@/views/finance/rechargeRecord'),
      //   name: 'rechargeRecord',
      //   meta: { title: '充值记录', icon: 'guide' }
      // },
      {
        id: 603,
        path: 'refund',
        component: () => import('@/views/finance/refund'),
        name: 'refund',
        meta: { title: '退款管理', icon: 'guide' }
      },
      {
        id: 604,
        path: 'parkingReconciliation',
        component: () => import('@/views/finance/parkingReconciliation'),
        name: 'parkingReconciliation',
        meta: { title: '车场对账', icon: 'guide' }
      },
      {
        id: 605,
        path: 'payment',
        component: () => import('@/views/finance/payment'),
        name: 'payment',
        meta: { title: '打款', icon: 'guide' }
      }
    ]
  },
  {
    // id: 7,
    path: '/shop',
    component: Layout,
    name: 'shop',
    meta: {
      title: '商户管理',
      icon: 'nested'
    },
    children: [
      {
        // id: 701,
        path: 'business--manage',
        component: () => import('@/views/shop/businessManage/index'),
        name: 'business--manage',
        meta: { title: '商户管理', icon: 'guide' }
      },
      {
        // id: 701,
        path: 'shop--manage',
        component: () => import('@/views/shop/shopManage/index'),
        name: 'shop--manage',
        meta: { title: '店铺管理', icon: 'guide' }
      },
    ]
  },
  // {
  //   id: 7,
  //   path: '/system',
  //   component: Layout,
  //   name: 'System',
  //   meta: {
  //     title: '系统管理',
  //     icon: 'nested'
  //   },
  //   children: [
  //     {
  //       id: 701,
  //       path: 'user',
  //       component: () => import('@/views/system/user/index'),
  //       name: 'User',
  //       meta: { title: '用户管理', icon: 'guide' }
  //     },
  //     {
  //       id: 702,
  //       path: 'role',
  //       component: () => import('@/views/system/role/index'),
  //       name: 'Role',
  //       meta: { title: '角色管理', icon: 'guide' }
  //     }
  //   ]
  // },
  {
    id: 7,
    path: '/feedback',
    component: Layout,
    name: 'Feedback',
    meta: {
      title: '意见反馈',
      icon: 'nested'
    },
    children: [
      {
        id: 701,
        path: 'feedback',
        component: () => import('@/views/feedback/index'),
        name: 'feedback',
        meta: { title: '意见反馈', icon: 'guide' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
